﻿package com.d4p.iterator
{
	internal class CollectionReverseIterator implements IFIterator
	{
		private var idx:int 
		private var collection:IFCollection;
		
		public function CollectionReverseIterator(collection:IFCollection):void{
			
			this.collection = collection;
			this.idx = collection.getLength()-1
			//trace(idx);
		}
		public function remove():*
		{
			var result:* = collection.removeItemAt(++this.idx);
			return result;
		}
		
		public function hasNext():Boolean
		{
			return this.idx >= 0;
		}
		
		public function next():*
		{
			//trace(idx);
			var result:* = collection.getItemAt(this.idx--);
			return result;
			
		}
		public function replaceWith(item:*):int
		{
			trace("current iterator idx : " , idx);
			return this.collection.replaceWith(item, this.idx+1);
		}
			
	}
}